package com.zhy.sunmi.myView;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;

/**
 * @ClassName MyVIewPager
 * @Description TODO
 * @Author zhouhongyang
 * @DATE 2021/9/5 11:31 下午
 * @Version 1.0
 */
public class MyViewPager extends ViewPager {

    //定义一个变量，用来设置是否有切换动画，支持配置
    private boolean scroll = false;

    public MyViewPager(@NonNull Context context) {
        super(context);
    }

    public MyViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void setCurrentItem(int item, boolean smoothScroll) {
        //这里读取设置的值
        super.setCurrentItem(item, scroll);
    }

    @Override
    public void setCurrentItem(int item) {
        //这里读取设置的值
        super.setCurrentItem(item, scroll);
    }


    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return scroll && super.onTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return scroll && super.onInterceptTouchEvent(ev);
    }

    //设置方法
    public void setScroll(boolean scroll) {
        this.scroll = scroll;
    }

}
